package com.book.dao;

import com.book.entity.Book;
import com.book.entity.Borrow;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author zzw2000
 * @Date 2022年08月11日 9:32
 * @Description 描述
 */
public interface BookMapper {
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "bid", property = "bookId"),
            @Result(column = "title", property = "bookName"),
            @Result(column = "sid", property = "studentId"),
            @Result(column = "name", property = "studentName"),
            @Result(column = "time", property = "time"),
    })
    @Select("SELECT * FROM borrow,student,book WHERE borrow.sid=student.sid AND borrow.bid=book.bid")
    List<Borrow> getBorrowList();

    @Delete("DELETE FROM borrow WHERE id=#{id}")
    void delBorrow(int id);

    @Delete("DELETE FROM book WHERE bid=#{bid}")
    void delBook(int bid);

    @Select("SELECT * FROM book")
    List<Book> getBookList();

    @Insert("INSERT INTO borrow(sid, bid) values (#{sid},#{bid})")
    void addBorrow(@Param("sid") int sid, @Param("bid") int bid);

    @Update("UPDATE book SET status=#{flag} WHERE bid=#{bid}")
    void updateBookStatus(@Param("bid") int bid,@Param("flag") boolean flag);

    @Insert("INSERT INTO book(title, `desc`, price) VALUES (#{title},#{desc},#{price})")
    void addBook(@Param("title") String title, @Param("desc") String desc, @Param("price") Double price);

    @Select("SELECT COUNT(*) FROM book")
    Integer getBookQuantity();

    @Select("SELECT COUNT(*) FROM student")
    Integer getStudentQuantity();

    @Select("SELECT COUNT(*) FROM borrow")
    Integer getBorrowCount();
}
